package de.yellowshoes.tedx.net;

import java.util.List;

import android.util.Log;
import de.yellowshoes.tedx.TEDxConstants;
import de.yellowshoes.tedx.net.exception.CsvReaderException;

/**
 * Reads speaker infos from a csv file.
 * 
 * @author calibanatspace
 * 
 */
public class SpeakerReader
    {
    private String url = null;

    public SpeakerReader( String url )
        {
        this.url = url;
        }

    public void read()
        {
        CsvRemoteReader reader = new CsvRemoteReader( url, ",", 9 );
        List< Object[] > objectList = null;

        try
            {
            objectList = reader.read();
            }
        catch( CsvReaderException e )
            {
            Log.e( TEDxConstants.LOG_TAG, "Error while reading speakers.csv via url " + url, e );
            return;
            }

        if( objectList.size() > 0 )
            {
            objectList.remove( 0 );
            }

        for( Object[] objects : objectList )
            {
            String firstname = null;
            String lastname = null;
            String pictureurl = null;
            String description = null;

            if( objects.length > 3 )
                {
                firstname = ( String )objects[ 0 ];
                lastname = ( String )objects[ 1 ];
                pictureurl = ( String )objects[ 2 ];
                description = ( String )objects[ 3 ];
                }

            System.out.println( firstname + " " + lastname + "; " + pictureurl + "; " + description );
            }
        }

    }
